<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="com.pmsco.pms.core.constant.PmsConstant"%>
<%@ page import="com.pmsco.pms.util.BundleUtil"%>
<%@ include file="/WEB-INF/import/tagLibs.jsp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<script>
	    $(function() {
	        $("button").button();
	    });
    </script>
</head>
<body class="pmsMainBody">
	<table class="pmsMainTable">
		<tr class="pmsMainTableWrapperTd">
			<td>
			    <table class="tableForm" cellpadding="0" cellspacing="0">
			    	<input type="hidden" id="id" name="id" value="${command.id}"/>
			    	<c:if test="${errorMessage != null}">
			    		<tr><td colspan="2" ="tableFormLabelRequired"><spring:message code="${errorMessage}"/></td></tr>	
			    	</c:if>
			    	<tr>
			    		<td>
			    			<table class="tableForm" cellpadding="0" cellspacing="0">
			    				<tr>
									<td class="tableFormLabel"><label class="tableFormLabelRequired">*&nbsp;</label><spring:message code="medicine.name"/></td>
									<td><input type="text" class="talbeFormTextBox" id="name" name="name" value="${command.name}" size="50" required/></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><label class="tableFormLabelRequired">*&nbsp;</label><spring:message code="medicine.enName"/></td>
									<td><input type="text" class="talbeFormTextBox" id="enName" name="enName" value="${command.enName}" size="50" required/></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><label class="tableFormLabelRequired">*&nbsp;</label><spring:message code="medicine.visa"/></td>
									<td><input type="text" class="talbeFormTextBox" id="visa" name="visa" value="${command.visa}" size="50" required/></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><spring:message code="medicine.dispenseType"/></td>
									<td><input type="text" class="talbeFormTextBox" id="dispenseType" name="dispenseType" value="${command.dispenseType}" size="50"/></td>
								</tr>	
								<tr>
									<td class="tableFormLabel"><spring:message code="medicine.distributor"/></td>
									<td><input type="text" class="talbeFormTextBox" id=distributor name="distributor" value="${command.distributor}" size="50"/></td>
								</tr>	
			    			</table>
			    		</td>
			    		<td>
		    				<table class="tableForm" cellpadding="0" cellspacing="0">
								<tr>
									<td class="tableFormLabel"><label class="tableFormLabelRequired">*&nbsp;</label><spring:message code="medicine.ingredient"/></td>
									<td><textarea class="talbeFormTextBox" id="ingredient" name="ingredient" cols="50" rows="2" required>${command.ingredient}</textarea></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><label class="tableFormLabelRequired">*&nbsp;</label><spring:message code="medicine.directions"/></td>
									<td><textarea class="talbeFormTextBox" id="directions" name="directions" cols="50" rows="2" required>${command.directions}</textarea></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><spring:message code="medicine.manufacturer"/></td>
									<td><input type="text" class="talbeFormTextBox" id="manufacturer" name="manufacturer" value="${command.manufacturer}" size="50"/></td>
								</tr>
								<tr>
									<td class="tableFormLabel"><spring:message code="medicine.importer"/></td>
									<td><input type="text" class="talbeFormTextBox" id="importer" name="importer" value="${command.importer}" size="50"/></td>
								</tr>
			    			</table>
			    		</td>
			    	</tr>
					<tr>
						<td colspan="2">
							<table class="tableForm" cellpadding="0" cellspacing="0">
								<c:set var="cols" value="3"/>
								<tr>
									<td colspan="${cols}" class="tableFormLabelLeft"><spring:message code="medicine.categoryAndSubcategory"/></td>
								</tr>
								<c:set var="count" value="0"/>
								<c:forEach var="categoryItem" items="${categoryList}">
									<c:set var="selectedCategory" value="false"/>
									<c:forEach var="medicineCategory" items="${command.medicineCategories}">
										<c:if test="${medicineCategory.category.id == categoryItem.id}">
											<c:set var="selectedCategory" value="true"/>
										</c:if>
									</c:forEach>
									<c:if test="${count % cols == 0}">
										<tr>
									</c:if>
									<td valign="top">
										<table class="tableForm" cellpadding="0" cellspacing="0" width="100%">
											<tr>
												<td>
													<input type="checkbox" <c:if test="${selectedCategory}">checked="checked"</c:if> class="talbeFormTextBox" id="category${categoryItem.id}" name="category" value="${categoryItem.id}" onclick="toggleSubCategories(${categoryItem.id}, ${fn:length(categoryItem.subCategories)})"/>
													<label for="category${categoryItem.id}">${categoryItem.name}</label>
												</td>
											</tr>
											<c:set var="subCount" value="0"/>
											<c:forEach var="subCategoryItem" items="${categoryItem.subCategories}">
												<c:set var="selectedSubCategory" value="false"/>
												<c:set var="mainSubCategory" value="false"/>
												<c:forEach var="medicineCategory" items="${command.medicineCategories}">
													<c:if test="${medicineCategory.subCategory.id == subCategoryItem.id}">
														<c:set var="selectedSubCategory" value="true"/>
													</c:if>
													<c:if test="${medicineCategory.subCategory.id == subCategoryItem.id && medicineCategory.mainCategory == 'Y'}">
														<c:set var="mainSubCategory" value="true"/>
													</c:if>
												</c:forEach>
												<tr>
													<td>
														&nbsp;&nbsp;&nbsp;
														<input type="radio" <c:if test="${mainSubCategory}">checked="checked"</c:if> class="talbeFormTextBox" id="${categoryItem.id}mainSubCategory${subCount}" name="mainSubCategory" value="${categoryItem.id}_${subCategoryItem.id}" title="Main Category" <c:if test="${!selectedSubCategory}">disabled="disabled"</c:if>/>
														<input type="checkbox" <c:if test="${selectedSubCategory}">checked="checked"</c:if> class="talbeFormTextBox" id="${categoryItem.id}subCategory${subCount}" name="subCategory" value="${categoryItem.id}_${subCategoryItem.id}" <c:if test="${!selectedSubCategory && !selectedCategory}">disabled="disabled"</c:if> onclick="toggleMainSubCategory(${categoryItem.id},${subCount})"/>
														<label for="subCategory${subCategoryItem.id}">${subCategoryItem.name}</label>
													</td>
												</tr>
												<c:set var="subCount" value="${subCount + 1}"/>
											</c:forEach>
										</table>
									</td>
									<c:if test="${count % cols == cols - 1}">
										</tr>
									</c:if>
									<c:set var="count" value="${count + 1}"/>
								</c:forEach>
							</table>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<table align="center" cellpadding="0" cellspacing="0">
								<tr>
									<td>
										<button class="tableFormButton" onclick="return submitAction('<%=PmsConstant.saveMedicine_JspUrl%>', true)"><spring:message code="button.save"/></button>
									</td>
									<td>
										<button class="tableFormButton" onclick="return confirmAction('<%=PmsConstant.listMedicine_JspUrl%>', cancelMedicineDetailTitle, cancelMedicineDetailMessage)"><spring:message code="button.cancel"/></button>
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</body>
</html>